package com.groupsix.controller;

import com.groupsix.entity.Visitor;
import com.groupsix.utils.PageInfo;
import com.groupsix.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 参观者控制器
 * @date 2021/10/16 15:28
 */
@Controller
public class VisitorController {
    //依赖注入
    @Autowired
    private VisitorService visitorService;
    /**
     * 分页查询
     * pageIndex 当前页码
     * pageSize  显示条数
     */
    @RequestMapping("/findVisitor.action")
    public String findVisitor(String vName, Integer vPhone , Integer pageIndex,
                              Integer pageSize, Model model) {

        PageInfo pi = visitorService.findPageInfo(vName,vPhone,
                pageIndex,pageSize);
        model.addAttribute("pi",pi);
        model.addAttribute("vName",vName);
        return "visitor_list";
    }

    /**
     * 添加学生信息
     */

    @RequestMapping("/addVisitor.action")
    @ResponseBody
    public String addStudent(@RequestBody Visitor visitor) {
        int v = visitorService.addVisitor(visitor);
        return "visitor_list";
    }

}
